<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Marko
 * Date: 5/20/13
 * Time: 1:24 AM
 * To change this template use File | Settings | File Templates.
 */


function find_lang_in_string($str, $lang)
{
    if(substr($str,0,4)=='<!--'){
        $start = '<!--:'.$lang.'-->';
        $end = '<!--:-->';

        $str = " ".$str;
        $ini = strpos($str,$start);
        if ($ini == 0) return "";
        $ini += strlen($start);
        $len = strpos($str,$end,$ini) - $ini;
        $fin = substr($str,$ini,$len);
        return $fin;
    }else return $str;
}


function get_string_between($string, $start, $end){
    $string = " ".$string;
    $ini = strpos($string,$start);
    if ($ini == 0) return "";
    $ini += strlen($start);
    $len = strpos($string,$end,$ini) - $ini;
    return substr($string,$ini,$len);
}

function get_filename_extension($filename){
    $ext = explode('.', $filename);
    return $ext[count($ext) - 1];
}

function strip_filename_extension($filename){
    $ext = explode('.', $filename);
    array_pop($ext);
    $name = implode($ext, '.');
    return $name;
}

function toAscii($str, $replace=array(), $delimiter='-') {
    if( !empty($replace) ) {
        $str = str_replace((array)$replace, ' ', $str);
    }

    $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
    $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
    $clean = strtolower(trim($clean, '-'));
    $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);

    return $clean;
}